﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Arcanea.StateEditor.XmlObjects;

namespace Arcanea.StateEditor
{

    public partial class BulleTexte : UserControl
    {

        private BulleTexteXml modele = new BulleTexteXml();
        public BulleTexteXml Modele
        {
            get
            {
                return modele;
            }
            set
            {
                modele = value;
                textBoxTexte.Text = modele.Texte;
                this.Location = new Point(modele.X, modele.Y);
            }
        }

        public BulleTexte()
        {
            InitializeComponent();
        }

        //private int guid = 0;
        //public int GUID
        //{
        //    get { return guid; }
        //    set { guid = value; }
        //}
        //private List<int> guidLink = new List<int>();
        //public List<int> GUIDLink
        //{
        //    get { return guidLink; }
        //    set { guidLink = value; }
        //}

        //public List<int> ListGuidLink = new List<int>();

        //public string Texte
        //{
        //    get { return textBox1.Text; }
        //    set { textBox1.Text = value; }
        //}

        public void GenerateGuid()
        {
            modele.GUID = this.GetHashCode();
        }

        private bool selected = false;
        public bool Selected 
        {
            get { return selected; }
        }

        private bool Clicked = false;
        private int XClicked = 0;
        private int YClicked = 0;
        private int DeltaX = 0;
        private int DeltaY = 0;

        private void Mouse_Click(object sender, EventArgs e)
        {
            if (DeltaX < 10 && DeltaY < 10)
            {
                selected = !selected;
                if (selected)
                {
                    this.pictureBoxCadre.BackColor = Color.FromKnownColor(KnownColor.ActiveCaption);
                    this.textBoxTexte.BackColor = Color.FromKnownColor(KnownColor.ActiveCaption);
                    this.buttonDelete.BackColor = Color.FromKnownColor(KnownColor.ActiveCaption);
                }
                else
                {
                    this.pictureBoxCadre.BackColor = Color.FromKnownColor(KnownColor.Control);
                    this.textBoxTexte.BackColor = Color.FromKnownColor(KnownColor.Control);
                    this.buttonDelete.BackColor = Color.FromKnownColor(KnownColor.Control);

                }
            }
        }

        private void Mouse_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {

                Clicked = true;
            }
            XClicked = e.X;
            YClicked = e.Y;
            DeltaX = 0;
            DeltaY = 0;
        }

        private void Mouse_MouseUp(object sender, MouseEventArgs e)
        {
            Clicked = false;
        }

        private void Mouse_MouseMove(object sender, MouseEventArgs e)
        {
            if (Clicked)
            {
                DeltaX += XClicked;
                DeltaY += YClicked;
                this.Left += e.X - XClicked;
                this.Top += e.Y - YClicked;
                if (this.Parent != null)
                    this.Parent.Refresh();
            }
        }

        private void BulleTexte_Move(object sender, EventArgs e)
        {
            modele.X = this.Location.X;
            modele.Y = this.Location.Y;
        }

        private void textBoxTexte_TextChanged(object sender, EventArgs e)
        {
            modele.Texte = textBoxTexte.Text;
        }

        private void buttonDelete_Click(object sender, EventArgs e)
        {
            this.modele = null;
            this.Parent.Refresh();
        }
    }
}
